package com.ssm.zy.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @author 郑智辰~
 * @version 1.0
 */
@Data
public class Result<T> implements Serializable {

    private Boolean isSuccess;
    private Integer code;
    private String message;
    private T data;

    public Result(Boolean isSuccess ,Integer code, String message, T data) {
        this.isSuccess = isSuccess;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(ResultCode resultCode,T data) {
        this.isSuccess = resultCode.getIsSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    public Result(ResultCode resultCode) {
        this.isSuccess = resultCode.getIsSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = null;
    }

    public static Result ok() {
        return new Result(true,200,"ACTION OK",null);
    }

    public static Result err() {
        return new Result(false,400,"ACTION ERROR",null);
    }

    public static Result errUsername() {
        return new Result(false,400,"用户名重复",null);
    }

    public static Result errPhone() {
        return new Result(false,400,"手机号重复",null);
    }

    public static Result ok(ResultCode resultCode) {
        return new Result(resultCode);
    }

    public static Result err(ResultCode resultCode) {
        return new Result(resultCode);
    }
}
